package com.milhouz.quizzdroid.bean;

import android.os.Parcel;
import android.os.Parcelable;

public class Player implements Parcelable {

	private int playerNumber;
	private Score score;

	public Player() {
	}

	public Player(final int playerNumber) {
		this.playerNumber = playerNumber;
		this.score = new Score();
	}

	public int getPlayerNumber() {
		return playerNumber;
	}

	public String getPlayerScore() {
		StringBuilder sb = new StringBuilder();
		sb.append(score.getNbCorrectResponses()) //
				.append("/") //
				.append(score.getNbQuestions());
		return sb.toString();
	}

	public Score getScore() {
		return score;
	}

	@Override
	public void writeToParcel(Parcel parcel, int flags) {
		parcel.writeInt(playerNumber);
		parcel.writeParcelable(score, flags);
	}

	public static final Creator<Player> CREATOR = new Creator<Player>() {
		@Override
		public Player createFromParcel(Parcel source) {
			Player p = new Player();
			p.playerNumber = source.readInt();
			p.score = source.readParcelable(Score.class.getClassLoader());
			return p;
		}

		@Override
		public Player[] newArray(int arg0) {
			return null;
		}
	};

	@Override
	public int describeContents() {
		return 0;
	}

}
